package com.lgs7907.simplestockinfo;

import android.app.Application;
import android.content.Context;
import android.widget.Toast;

/**
 * 全局Application
 */
public class MyApplication extends Application {

	private static MyApplication instance;

	private static Context context;
	private static Toast mToast;
	private static StockDb stockDb;

	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		context = getApplicationContext();

		stockDb = new StockDb(context);
	}

	public static MyApplication getInstance() {
		if (null == instance) {
			instance = new MyApplication();
		}
		return instance;
	}

	// 遍历所有Activity 并finish
	public static void exit() {
		System.exit(0);
	}

	public static StockDb getStockDb() {
		return getInstance().stockDb;
	}

	/** MyApplication.ShowToast(msg, Toast.LENGTH_SHORT,Gravity.BOTTOM); */
	public static void ShowToast(String value, int duration, int gravity) {
		if (mToast == null) {
			mToast = Toast.makeText(context, value, duration);
		} else {
			mToast.setDuration(duration);
			mToast.setText(value);
		}
		mToast.setGravity(gravity, 0, 0);
		mToast.show();
	}

}
